<!--
 * @Author: your name
 * @Date: 2020-02-25 13:32:39
 * @LastEditTime: 2020-02-28 11:25:55
 * @LastEditors: Please set LastEditors
 * @Description: In User Settings Edit
 * @FilePath: \福路德扫码系统\html\cksm.html
 -->
<!doctype html>
<html>

<head>
    <meta charset="utf-8">
    <meta name="viewport"
        content="maximum-scale=1.0,minimum-scale=1.0,user-scalable=0,width=device-width,initial-scale=1.0,viewport-fit=cover" />
    <meta name="format-detection" content="telephone=no,email=no,date=no,address=no">
    <title>Hello APP</title>
    <link rel="stylesheet" type="text/css" href="../../css/vant.css">
    <link rel="stylesheet" type="text/css" href="../../css/base.css" />
    <link rel="stylesheet" type="text/css" href="../../css/local.css" />
    <link rel="stylesheet" type="text/css" href="../../font/iconfont.css" />
    <link rel="stylesheet" href="../../script/elementui/lib/theme-chalk/index.css?t=1">
    <link href="../../script/elementui/vue-element-table.css" rel="stylesheet" />
    <script type="text/javascript" src="../../script/jquery.js"></script>
    <script type="text/javascript" src="../../script/layer/layer.js"></script>
    <script type="text/javascript" src="../../script/vue.min.js"></script>
    <script type="text/javascript" src="../../script/vant.min.js"></script>
    <script type="text/javascript" src="../../script/fastclick.js"></script>
    <script src="../../script/elementui/lib/index.js?t=1"></script>
    <script src="../../script/elementui/vue-element-bigdata-table.min.js?t=4"></script>
    <script type="text/javascript" src="../../script/base.js"></script>
    <script type="text/javascript" src="../../script/JSLINQ.js"></script>
    <script type="text/javascript" src="../../script/ajaxFileUpload.js"></script>

    <style type="text/css">

    </style>
</head>

<body>
    <div id="app" v-cloak>
        <div class="box">

            <van-nav-bar id="van-nav-bar" :title="titleName" left-arrow @click-left="onClickLeft">
                <div slot="right">
                    <span slot="right" @click="openScan" v-if="!isPDA">
                        <img src="../../image/scan.png" />
                    </span>
                    <span slot="right" @click="openPrint" v-if="isPDA && printConfig">
                        <img src="../../image/print.png" />
                    </span>
                </div>
            </van-nav-bar>
        </div>

    </div>
</body>
<script type="text/javascript">
    var vm;
    apiready = function () {

        api.addEventListener({
            name: 'refreshList'
        }, function (ret, err) {
            vm.refreshList();
        })

        vm = new Vue({
            el: '#app',
            data: {
                titleName: api.pageParam.titleName,
                isPDA: api.deviceModel.indexOf('PDA') > -1 ? true : false,
                serverIP: APP.serverIP(),
                printConfig: '',
            },
            created: function () {
            },
            methods: {
                onClickLeft() {
                    api.closeWin();
                },
                //摄像头扫描事件
                openScan() {
                    var resultList = api.hasPermission({
                        list: ['camera']
                    });
                    if (resultList[0].granted) {
                        // 已授权，可以继续下一步操作
                        FNScanner.open({
                            autorotation: true
                        }, function (ret, err) {
                            if (ret) {
                                if (ret.content) {
                                    api.sendEvent({
                                        name: 'scanHandler',
                                        extra: {
                                            scanData: ret.content
                                        }
                                    })
                                }
                            } else {
                                vm.$toast('扫描失败');
                            }
                        });
                    } else {
                        api.confirm({
                            msg: '应用需要您的授权才能访问相机',
                            buttons: ['取消', '去设置']
                        }, function (ret) {
                            if (ret.buttonIndex == 2) {
                                api.requestPermission({
                                    list: ['camera'],
                                }, function (res) {
                                    if (res.list[0].granted) {
                                        // 已授权，可以继续下一步操作
                                        FNScanner.open({
                                            autorotation: true
                                        }, function (ret, err) {
                                            if (ret) {
                                                if (ret.content) {
                                                    api.sendEvent({
                                                        name: 'scanHandler',
                                                        extra: {
                                                            scanData: ret.content
                                                        }
                                                    })
                                                }
                                            } else {
                                                vm.$toast('扫描失败');
                                            }
                                        });
                                    }
                                });
                            }
                        });
                    }


                    // var hwScanner = api.require('hwScanner');
                    // hwScanner.defaultScanner({
                    //     formatType: 'ALL'
                    // }, function (ret) {
                    //     if (ret.status) {
                    //         api.sendEvent({
                    //             name: 'scanHandler',
                    //             extra: {
                    //                 scanData: ret.result
                    //             }
                    //         })
                    //     }
                    //     else {
                    //         vm.$toast('扫描失败');
                    //     }
                    // });
                },

                //打开打印
                openPrint() {
                    if (vm.printConfig) {
                        var script = vm.printConfig.replace(/\['/g, "vm.formData['");
                        script = script.replace(/\["/g, "vm.formData[\"");
                        eval(script);
                    }
                },

            }

        })
    };
</script>

</html>